//file onchange
function onPreviewImg(fileObj, imgPreviewId) {
    if ( fileObj.files  == null) {
        iePreview(fileObj, imgPreviewId);
    } else {
        noIEPreviewImg(fileObj, imgPreviewId);
    }
    var imgSource=$('#imgSource');
    if(imgSource)imgSource.val('upload');
}

//IE浏览器的图片预览
function iePreview(fileObj, imgPreviewId) {
    fileObj.select();
    // 当前是否是iframe页面
    if(top!=this){
        window.parent.document.body.focus();
    }else{
        fileObj.blur();
    }
    var src = document.selection.createRange().text;
    document.selection.empty();
    if(typeof(imgPreviewId)=="string"){
        $("#"+imgPreviewId).empty().attr("style", "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='" + src + "')");
        if( $("#"+imgPreviewId).attr('src') ){
            $("#"+imgPreviewId).attr('src','');
        }
    }else{
        $(imgPreviewId).empty().attr("style", "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='" + src + "')");
        if( $(imgPreviewId).attr('src') ){
            $(imgPreviewId).attr('src','');
        }
    }

}

//火狐 谷歌浏览器的图片预览
function noIEPreviewImg(fileObj, imgPreviewId) {
    var  imgPreview = document.getElementById(imgPreviewId);
    if (fileObj.files && fileObj.files[0]) {
        var reader = new FileReader();
        reader.onload = function(evt) {
            imgPreview.src = evt.target.result;
        };
        reader.readAsDataURL(fileObj.files[0]);
    } else {
        fileObj.select();
        var src = document.selection.createRange().text;
        console.log(src);
        imgPreview.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
    }
}
